def find_lower_left_contour(matrix):
    points = []
    # 找出所有边缘点
    for i in range(len(matrix)):
        for j in range(len(matrix[0])):
            if matrix[i][j] == 1:
                # 检查是否是边缘点
                if (i > 0 and matrix[i-1][j] == 0) or \
                   (i < len(matrix)-1 and matrix[i+1][j] == 0) or \
                   (j > 0 and matrix[i][j-1] == 0) or \
                   (j < len(matrix[0])-1 and matrix[i][j+1] == 0):
                    points.append((j, i))  # 注意顺序为 (x, y)

    # 按 (x, y) 排序
    points.sort()

    # 提取左下轮廓
    contour = []
    current_point = points[0]
    contour.append(current_point)

    for point in points[1:]:
        if point[0] > current_point[0] or (point[0] == current_point[0] and point[1] > current_point[1]):
            contour.append(point)
            current_point = point

    return contour

# 示例使用
matrix = [
    [0, 0, 0, 0, 0],
    [0, 1, 1, 1, 0],
    [0, 1, 1, 1, 0],
    [0, 0, 1, 0, 0],
    [0, 0, 0, 0, 0]
]

contour = find_lower_left_contour(matrix)
print(contour)

# (1,1) (2,1) (3,2) 